#ifndef READLINE_HH_
# define READLINE_HH_

# include <string>
# include <vector>

# include "constants/common.hh"
# include "constants/chat.hh"
# include "tools/Color.hh"

/** each Client have it's own ReadLine instance
 ** the Readline exists only to help navigating in the chat
 */
class ReadLine
{
public:
  ReadLine();
  ~ReadLine();

  /** reinit between each input end (keep history, ...)
   */
  void init();

  void clear();

  // C-c || Escape
  /** returns true on user quit request
   */
  bool interruptChat();


  /** cut all text right from cursor
   ** equivalent of Unix C-k
   */
  void cutCursorRight();


  /** paste _circularBuffer[Index]
   ** paste from cursor to end of _circularBuffer[Index] or input
   */
  void paste();


  void printCursor();


  /** add a red block at end of input + 1
   */
  void printEndOfInput();


  /** print last user input
   */
  void printInput();

  /** returns autocomplettion list
   */
  std::vector<std::string>* autoComplete();

  void rmPreviousChar();

  void rmLastChar();

  // blit sprite, 1 char size of _highlightColor color
  void highlightSelection();

  // __________ cursor motion
  void moveCursorLeft();
  void moveCursorRight();

  // usefull if allowing multi-lines input
  void moveCursorUp();
  void moveCursorDown();


  /** also add '\n'
   **   (on S-Enter)
   ** only CHAT_MAX_LINEWRAPS treatment (to avoid flood)
   */
  void addChar(char c);

  /** add in circular buffer
   ** from mark to cursor
   */
  void copy();


  /** called on M-y
   ** increments _circularBufferIndex
   */
  void circleThroughCircularBuffer();


  /** add in circular buffer
   ** clear input buffer from cursor position to end
   */
  void cut();


  /** sets mark at cursor position
   */
  void markRegion();


  /** send user input to server
   */
  void sendInput();


  /// loops and catch user keyboard input
  void inChat();



// cd ad a vector of linewraps positions to calc pos cursor down, ...

private:
  /// current user input string
  std::string _currentInput; /// is the 'real' user's input
  unsigned int _currentInputIndex;
  unsigned char _nbLineWraps; /// number of linewraps in current input

  /// true if we're in mark mode
  // cd pipe these flags
  bool _highlighting;
  bool _command; /// are we typing a command (1st == '/')
  bool _mark;

  unsigned char _markPosition;
  unsigned char _cursorPosition;

  /// chat line length (in char)
  unsigned char _lineLength;

  /// current position in _circularBufferIndex
  unsigned char _circularBufferIndex;
  std::vector<std::string> _circularBuffer; // 16

  unsigned char _historyIndex;
  std::vector<std::string> _history; // 32

  // though, user's right have to be tested on the Server
  // *BEFORE* executing it

  std::vector<std::string> _cmdList;

  // colors
  unsigned char _cursorShape; /// cursor shape (block, _, -)
  Color _cursorColor; /// cursor color
  Color _currentFontColor; /// =f(current input [quotting, ...])
  Color _highlightColor; /// highlighted zone color

  unsigned char _nbChars;

  e_chat_font _fontType;
};

#endif /* !READLINE_HH_ */
